package com.hsq.file_;

import java.io.File;
import java.io.IOException;
import java.util.Date;

public class FileTest {
    public static void main(String[] args) throws IOException {
        String fileName = "D:\\git_turtle\\news1.txt";
        File myFile = new File(fileName);
        myFile.createNewFile();
        if (!myFile.exists()){
            System.err.println(fileName + "没找到");
        }
        if (myFile.isDirectory()){
            System.err.println("文件对象" + myFile.getName() + "是目录");
            File myData = new File("mydata");
            if (!myData.exists()){
                myData.mkdir();
                System.out.println("目录" + myData.getAbsolutePath() + "是目录");
            }
            return ;
        }
        if (myFile.isFile()){
            System.out.println("文件对象" + myFile.getAbsolutePath());
            System.out.println("文件字节数:" + myFile.length());
            System.out.println("文件是否可读:" + myFile.canRead());
            if (myFile.canWrite()) {
                System.out.println("设置文件为只读:" + myFile.setReadOnly());
            }
            System.out.println("文件是否可写：" + myFile.canWrite());
            Date modifyDate = new Date(myFile.lastModified());
            System.out.println("文件上次修改的时间:" + modifyDate.toString());
            myFile.setWritable(true);

        }
    }
}
